﻿using System;
using System.Collections.Generic;
using VeMayBayDTO;
using System.Data;
namespace VeMayBayDAO
{
    public  class DonGiaDAO
    {
        public static List<DonGiaDTO> GetDonGiaAll()
        {
            //Lấy MaDonGia,Tên san bay di,tên san bay den,tên hạng vé,giá tiến
            List<DonGiaDTO> list = new List<DonGiaDTO>();
            string query = "Select * From DonGia ";
            try
            {
                DataTable dt = DataProvider.ExecQuery(query);
                foreach(DataRow dr in dt.Rows )
                {
                    DonGiaDTO dg = new DonGiaDTO();
                    dg.MaDonGia =int.Parse( dr["maDonGia"].ToString());
                    dg.MaHanhTrinh = int.Parse(dr["maHanhTrinh"].ToString ());
                    dg.MaHangVe = int.Parse(dr["maHangVe"].ToString ());
                    dg.GiaTien = double.Parse(dr["giaTiem"].ToString ());
                    list.Add(dg);
                    
                }
            }
            catch(Exception ex)
            {
                throw ex;
            }
            return list;
        }

        public static DataTable GetDonGiaByChuyenBay(ChuyenBayDTO cb,int mahangve)
        {
            DataTable dt = new DataTable();
            string query = @"select dg.MaDonGia,dg.giatien
                            from DonGia dg , lichchuyenbay cb
                            where dg.mahangve = " + mahangve + " and dg.mahanhtrinh = cb.mahanhtrinh and cb.machuyenbay = " + cb.MaChuyenBay + "";
            dt = DataProvider.ExecQuery(query);
            return dt;

        }
        public static DonGiaDTO GetDongiaByHanhtrinh(int id)
        {
            DonGiaDTO dg = new DonGiaDTO();

            return dg;
        }
        public static DonGiaDTO GetDongiaById(int id)
        {
            DonGiaDTO dg = new DonGiaDTO();
            return dg;
        }
        public static bool ThemDonGia(DonGiaDTO dg)
        {
            return true;
        }
        public static bool CapNhatDG(DonGiaDTO dg)
        {
            return true;//
        }
        public static bool HuyDonGia(string id)
        {
            return true;
        }

    }
}
